import base64
import logging
from typing import Optional
from .interfaces import IVideoEncoder
from .exceptions import VideoEncodingError

logger = logging.getLogger(__name__)

class VideoEncoder(IVideoEncoder):
    """视频编码器实现"""
    
    def encode_video(self, video_path: str) -> str:
        """将视频文件编码为base64"""
        try:
            with open(video_path, "rb") as video_file:
                return base64.b64encode(video_file.read()).decode("utf-8")
        except Exception as e:
            logger.error(f"视频编码失败: {str(e)}")
            raise VideoEncodingError(f"视频编码失败: {str(e)}") 